package com.ihr360.payroll.controller.staff;

import com.ihr360.commons.vo.PageData;
import com.ihr360.commons.vo.ResultInfo;
import com.ihr360.maven.plugin.ModuleCodeStore;
import com.ihr360.maven.plugin.annotation.FunctionDefinition;
import com.ihr360.maven.plugin.annotation.ModuleDefinition;
import com.ihr360.payroll.entity.staff.StaffPayrollInfoJournalEntity;
import com.ihr360.payroll.request.StaffPayrollInfoJournalRequest;
import com.ihr360.payroll.service.staff.StaffPayrollInfoJournalService;
import com.ihr360.shared.advice.response.DisableResponseAdvice;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(value = "员工薪资日志相关接口")
@RestController
@RequestMapping("/staffPayrollInfoJournals")
@ModuleDefinition(mainModuleCode = ModuleCodeStore.Module.SALARY_CODE, mainModuleName = ModuleCodeStore.Module.SALARY_NAME,
        subModuleCode = ModuleCodeStore.Module.Salary.STAFF_PAY_ROLLINFO_CODE, subModuleName = ModuleCodeStore.Module.Salary.STAFF_PAY_ROLLINFO_NAME)
public class StaffPayrollInfoJournalController {

    @Autowired
    private StaffPayrollInfoJournalService staffPayrollInfoJournalService;

    @ApiOperation(value = "分页查询所有薪资调整记录")
    @PostMapping(value = "/list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @FunctionDefinition(functionName = "分页查询所有薪资调整记录", functionCode = ModuleCodeStore.Function.VIEW)
    public PageData<StaffPayrollInfoJournalEntity> findAllJournals(@RequestBody StaffPayrollInfoJournalRequest param) {
        return staffPayrollInfoJournalService.findAllJournals(param);
    }


    @ApiOperation(value = "查询有权限的员工的薪资调整记录")
    @PostMapping(value = "/list/authDatas", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @FunctionDefinition(functionName = "查询有权限的员工的薪资调整记录", functionCode = ModuleCodeStore.Function.VIEW)
    @DisableResponseAdvice
    public PageData<StaffPayrollInfoJournalEntity> findAllAuthJournals(@RequestBody StaffPayrollInfoJournalRequest param) {
        return staffPayrollInfoJournalService.findAllJournals(param);
    }

    @ApiOperation(value = "分页查询某员工所有薪资调整记录")
    @GetMapping(value = "/detail/{staffId}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @FunctionDefinition(functionName = "分页查询某员工所有薪资调整记录", functionCode = ModuleCodeStore.Function.VIEW)
    public List<StaffPayrollInfoJournalEntity> getStaffJournalDetail(@PathVariable(name = "staffId") String staffId) {
        return staffPayrollInfoJournalService.getStaffJournalDetail(staffId);
    }

    @ApiOperation(value = "保存薪资调整记录")
    @PostMapping(value = "/save", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @DisableResponseAdvice
    @FunctionDefinition(functionName = "保存薪资调整记录", functionCode = ModuleCodeStore.Function.EDIT)
    public ResultInfo save(@RequestBody List<StaffPayrollInfoJournalEntity> journalToSave) {
        return staffPayrollInfoJournalService.save(journalToSave);
    }

}
